package com.tedu.servies;

import com.tedu.dao.NewsTypeDao;
import com.tedu.pojo.News;
import com.tedu.pojo.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * 党建信息类型的服务层组件
 */
@Service
public class NewsTypeServies {

    @Autowired
    NewsTypeDao dao;


    /**
     * 随机获取size个 党建信息类型数据
     * @param DATA
     * @return
     */
    public List<Type> getTypeBySize(int size){
        List<Type> list = new ArrayList<>();
        List<Type> allType = dao.getAllType();

        if(allType.size()<=size){
            return allType;
        }

        for (int i = 0; i < size; i++) {
            int j = new Random().nextInt(allType.size());
            Type type = allType.get(j);
            list.add(type);
            allType.remove(type);
        }
        return list;

    }
}
